//
//  HLIMKitMessageVideoChatContentView.m
//  YueYue
//
//  Created by hulu001 on 2024/1/12.
//

#import "HLIMKitMessageVideoChatContentView.h"

@interface HLIMKitMessageVideoChatContentView ()

@property (weak,    nonatomic) UIImageView *imageView;
@property (strong,  nonatomic) UILabel *label;

@end

@implementation HLIMKitMessageVideoChatContentView


- (instancetype)init
{
    self = [super init];
    
    if (self) {
        self.label = [UILabel.alloc init];
        self.label.font = [UIFont systemFontOfSize:16];
        self.label.textColor = UIColor.blackColor;
        self.label.textAlignment = NSTextAlignmentCenter;
        self.label.backgroundColor = UIColor.clearColor;
        [self addSubview:self.label];
        
        UIImageView *fileImage = [UIImageView.alloc initWithFrame:CGRectMake(0, 0, 24, 24)];
        [self addSubview:fileImage];
        self.imageView = fileImage;
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    UIEdgeInsets contentInsets = self.messageModel.contentViewInsets;
    
    CGFloat tableViewWidth = self.superview.width;
    CGSize contentsize         = [self.messageModel contentSize:tableViewWidth];
    CGRect labelFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width - 28, contentsize.height);
    self.label.frame = labelFrame;
    
    if (self.messageModel.message.isOutgoingMsg) {
        self.imageView.right = self.width-12;
    } else {
        self.imageView.left = 12;
        self.label.left = self.imageView.right + 4;
    }
    self.imageView.centerY = self.middleY;
    self.label.centerY = self.middleY;
}

- (void)refreshData:(HLIMKitMessageModel *)messageModel
{
    [super refreshData:messageModel];
    self.label.text = messageModel.message.text;
    
    NIMRtcCallRecordObject *callRecord = (NIMRtcCallRecordObject *)messageModel.message.messageObject;
    
    if (messageModel.message.isOutgoingMsg) {
        if (callRecord.callType == NIMRtcCallTypeAudio) {
            self.imageView.image = [UIImage imageNamed:@"im_audiochat_self"];
        } else {
            self.imageView.image = [UIImage imageNamed:@"im_camera_self"];
        }
        
        self.label.textColor = UIColor.blackColor;
    } else {
        if (callRecord.callType == NIMRtcCallTypeAudio) {
            self.imageView.image = [UIImage imageNamed:@"im_audiochat_self"];
        } else {
            self.imageView.image = [UIImage imageNamed:@"im_camera_self"];
        }
        self.label.textColor = UIColor.blackColor;
    }
}

@end
